package com.yf.controller.admin.article;

import java.util.List;
import java.util.Map;

import com.yf.vo.ThumbBackVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.entity.ThumbUserEntity;
import com.yf.service.article.ThumbUserService;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 点赞人Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Tue Aug 21 14:10:58 CST 2018
 */
@RestController
@RequestMapping("/thumbuser")
public class ThumbUserController {
    @Autowired
    private ThumbUserService thumbUserService;

    /**
     * 列表点赞人
     */
    @RequestMapping("/list")
    @RequiresPermissions("thumbuser:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<ThumbUserEntity> thumbUserList = thumbUserService.queryList(params);
        return R.ok(new PageInfo(thumbUserList));
    }

    /**
     * 查看点赞人
     */
    @SysLog("查看点赞人")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("thumbuser:info")
    public R info(@PathVariable("id") Long id) {
        ThumbUserEntity thumbUser = thumbUserService.get(id);

        return R.ok(thumbUser);
    }

    /**
     * 保存点赞人
     */
    @SysLog("保存点赞人")
    @RequestMapping("/save")
    @RequiresPermissions("thumbuser:save")
    public R save(ThumbUserEntity thumbUser) {
        thumbUserService.save(thumbUser);

        return R.ok(thumbUser);
    }

    /**
     * 修改点赞人
     */
    @SysLog("修改点赞人")
    @RequestMapping("/update")
    @RequiresPermissions("thumbuser:update")
    public R update(ThumbUserEntity thumbUser) {
        thumbUserService.update(thumbUser);

        return R.ok(thumbUser);
    }

    /**
     * 删除点赞人
     */
    @SysLog("删除点赞人")
    @RequestMapping("/delete")
    @RequiresPermissions("thumbuser:delete")
    public R delete(@RequestBody Long[]ids) {
        thumbUserService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有点赞人
     */
    @SysLog("所有点赞人")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ThumbUserEntity> thumbUserList = thumbUserService.queryList(params);

        return R.ok(thumbUserList);
    }

    /***********自定义开始***********/

    /**
     * back 点赞记录
     * @param params
     * @return
     */
    @RequestMapping("/thumbUserRecord")
    public R findThumbUserRecord(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<ThumbBackVo> list = thumbUserService.findThumbUserRecord(params);
        return R.ok(new PageInfo(list));
    }

}
